package com.power.sifa.statistics.model.vo;

import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.power.sifa.approve.model.enumeration.Tp_apptype;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * @ClassName HomeUndoEvent
 * @Author xiongzw
 * @Date 2023/11/3 9:27
 * @Description 待处理事件
 * @Version: 1.0
 **/

@Data
@NoArgsConstructor
@AllArgsConstructor
public class HomeUndoEvent {

    /**
     * applyid
     */
    private String applyid;
    /**
     * applycode 申请流水号
     */
    private String applycode;
    /**
     * acceptcode； 案号
     */
    private String acceptcode;
    /**
     * 任务id
     */
    private String taskid;
    /**
     * 行政复议状态
     * {@link com.power.sifa.approve.model.enumeration.St_admreview}
     */
    private Integer status;

    /**
     * 行政复议流程环节
     */
    private String process;

    /**
     * 创建时间
     */
    private String createtime;

    /**
     * 申请人
     */
    private String applyname;

    /**
     * 被申请人
     */
    private String targetname;

    /**
     * 程序类型
     */
    private Integer proctype;

    /**
     * 程序类型文本
     */
    private String proctype_text;

    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updatetime;

    /**
     * 剩余天数， >0 未延期， <0 已延期
     */
    private Integer leftDay;

    /**
     * 截止时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date enddate;

    public HomeUndoEvent(Map<String, Object> dataMap) {
        SimpleDateFormat timeSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat dateSdf = new SimpleDateFormat("yyyy-MM-dd");
        if (ObjectUtil.isNotNull(dataMap)) {
            if (dataMap.containsKey("applyid")) {
                this.applyid = ObjectUtil.isNotNull(dataMap.get("applyid")) ? dataMap.get("applyid").toString() : null;
            }
            if (dataMap.containsKey("applycode")) {
                this.applycode = ObjectUtil.isNotNull(dataMap.get("applycode")) ? dataMap.get("applycode").toString() : null;
            }
            if (dataMap.containsKey("acceptcode")) {
                this.acceptcode = ObjectUtil.isNotNull(dataMap.get("acceptcode")) ? dataMap.get("acceptcode").toString() : null;
            }
            if (dataMap.containsKey("taskid")) {
                this.taskid = ObjectUtil.isNotNull(dataMap.get("taskid")) ? dataMap.get("taskid").toString() : null;
            }
            if (dataMap.containsKey("status_bz") && ObjectUtil.isNotNull(dataMap.get("status_bz"))) {
                this.status = ObjectUtil.isNotNull(dataMap.get("status_bz")) ? Integer.parseInt(dataMap.get("status_bz").toString()) : null;
            }
            if (dataMap.containsKey("status_bs") && ObjectUtil.isNotNull(dataMap.get("status_bs"))) {
                this.status = ObjectUtil.isNotNull(dataMap.get("status_bs")) ? Integer.parseInt(dataMap.get("status_bs").toString()) : null;
            }
            if (dataMap.containsKey("process")) {
                this.process = ObjectUtil.isNotNull(dataMap.get("process")) ? dataMap.get("process").toString() : null;
            }
            if (dataMap.containsKey("createtime")) {
                this.createtime = ObjectUtil.isNotNull(dataMap.get("createtime")) ? dataMap.get("createtime").toString() : null;
            }
            if (dataMap.containsKey("applyname") && ObjectUtil.isNotNull(dataMap.get("applyname"))) {
                this.applyname = ObjectUtil.isNotNull(dataMap.get("applyname")) ? dataMap.get("applyname").toString() : null;
            }
            if (dataMap.containsKey("targetname_bs") && ObjectUtil.isNotNull(dataMap.get("targetname_bs"))) {
                this.targetname = ObjectUtil.isNotNull(dataMap.get("targetname_bs")) ? dataMap.get("targetname_bs").toString() : null;
            }
            if (dataMap.containsKey("targetname_bz") && ObjectUtil.isNotNull(dataMap.get("targetname_bz"))) {
                this.targetname = ObjectUtil.isNotNull(dataMap.get("targetname_bz")) ? dataMap.get("targetname_bz").toString() : null;
            }
            if (dataMap.containsKey("updatetime")) {
                try {
                    this.updatetime = ObjectUtil.isNotNull(dataMap.get("updatetime")) ? timeSdf.parse(dataMap.get("updatetime").toString()) : null;
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            if (dataMap.containsKey("enddate")) {
                try {
                    this.enddate = ObjectUtil.isNotNull(dataMap.get("enddate")) ? dateSdf.parse(dataMap.get("enddate").toString()) : null;
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            if (dataMap.containsKey("leftDay") && ObjectUtil.isNotNull(dataMap.get("leftDay"))) {
                this.leftDay = ObjectUtil.isNotNull(dataMap.get("leftDay")) ? Integer.valueOf(dataMap.get("leftDay").toString()) : null;
            }
            if (dataMap.containsKey("proctype_bs") && ObjectUtil.isNotNull(dataMap.get("proctype_bs"))) {
                this.proctype = ObjectUtil.isNotNull(dataMap.get("proctype_bs")) ? Integer.valueOf(dataMap.get("proctype_bs").toString()) : null;
            }
            if (dataMap.containsKey("proctype_bz") && ObjectUtil.isNotNull(dataMap.get("proctype_bz"))) {
                this.proctype = ObjectUtil.isNotNull(dataMap.get("proctype_bz")) ? Integer.valueOf(dataMap.get("proctype_bz").toString()) : null;
            }
            if (ObjectUtil.isNotNull(this.proctype) && this.proctype == Tp_apptype.EASY) {
                this.proctype_text = "简易程序";
            } else {
                this.proctype_text = "普通程序";
            }
        }

    }
}
